import { AttributeType } from './AttributeType';
import { ModifierType } from './ModifierType';
import { ModifierSource } from './ModifierSource';

// 装备效果配置
export interface EquipmentEffectConfig {
    type: ModifierType;
    value: number;
    source: ModifierSource;
    priority?: number;
    basedOnAttribute?: AttributeType;
}

// 装备配置
export interface EquipmentConfig {
    id: string;
    name: string;
    description: string;
    effects: Map<AttributeType, EquipmentEffectConfig[]>;
    requirements?: {
        level?: number;
        attributes?: Map<AttributeType, number>;
    };
}

// 装备配置表
export class EquipmentConfigTable {
    private static instance: EquipmentConfigTable;
    private configs: Map<string, EquipmentConfig>;

    private constructor() {
        this.configs = new Map();
        this.initializeDefaultConfigs();
    }

    public static getInstance(): EquipmentConfigTable {
        if (!EquipmentConfigTable.instance) {
            EquipmentConfigTable.instance = new EquipmentConfigTable();
        }
        return EquipmentConfigTable.instance;
    }

    public getConfig(id: string): EquipmentConfig | undefined {
        return this.configs.get(id);
    }

    public addConfig(config: EquipmentConfig): void {
        this.configs.set(config.id, config);
    }

    private initializeDefaultConfigs(): void {
        // 示例：血刃
        this.addConfig({
            id: 'bloodthirsty_blade',
            name: '血刃',
            description: '攻击力+140, 攻击力增加当前生命值的20%',
            effects: new Map([
                // 攻击力+140
                [AttributeType.Attack, [{
                    type: ModifierType.FLAT,
                    value: 140,
                    source: ModifierSource.EQUIPMENT,
                }]],
                // 攻击力增加当前生命值的20%
                [AttributeType.Attack, [{
                    type: ModifierType.ATTRIBUTE_BASED,
                    value: 0.2,
                    source: ModifierSource.EQUIPMENT,
                    basedOnAttribute: AttributeType.HP
                }]]
            ])
        });

        // 增加一把基于攻击力的装备
        this.addConfig({
            id: 'long_sword',
            name: '长剑',
            description: '攻击力增加+100',
            effects: new Map([
                [AttributeType.Attack, [{
                    type: ModifierType.FLAT,
                    value: 110,
                    source: ModifierSource.EQUIPMENT,
                }]]
            ])
        });

        // 示例：守护者之盾
        this.addConfig({
            id: 'guardian_shield',
            name: '守护者之盾',
            description: '防御力增加当前生命值的15%，生命值增加500点',
            effects: new Map([
                [AttributeType.Defense, [{
                    type: ModifierType.PERCENTAGE,
                    value: 0.15,
                    source: ModifierSource.EQUIPMENT
                }]],
                [AttributeType.HP, [{
                    type: ModifierType.FLAT,
                    value: 500,
                    source: ModifierSource.EQUIPMENT
                }]]
            ])
        });

        // 示例：疾风之靴
        this.addConfig({
            id: 'swift_boots',
            name: '疾风之靴',
            description: '移动速度增加30%，攻击速度增加20%',
            effects: new Map([
                [AttributeType.Speed, [{
                    type: ModifierType.PERCENTAGE,
                    value: 0.3,
                    source: ModifierSource.EQUIPMENT
                }]],
                [AttributeType.AttackSpeed, [{
                    type: ModifierType.PERCENTAGE,
                    value: 0.2,
                    source: ModifierSource.EQUIPMENT
                }]]
            ])
        });
    }
} 